﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Common/MasterPages/Dialog.Master"
    AutoEventWireup="true" CodeBehind="AddRoleMember.aspx.cs" Inherits="DMS.Web.Modules.SystemManagement.Organization.AddRoleMember" %>

<%@ Register Src="~/Common/Controls/SelectedValues.ascx" TagName="SelectedValues"
    TagPrefix="uc1" %>
<%@ Register Src="~/Common/Controls/UserList.ascx" TagName="UserList" TagPrefix="uc2" %>
<%@ Register Src="~/Common/Controls/DepartmentTree.ascx" TagName="DepartmentTree"
    TagPrefix="uc3" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PageTitle" runat="server">
    <asp:Literal ID="lb_title" runat="server"></asp:Literal>
    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainHolder" runat="server">
    <script type="text/javascript" src="/Resources/Scripts/jquery-1.4.1.js"></script>
    <script type="text/javascript" src="/Resources/Scripts/jquery.blockUI.js"></script>
    <style>
        .selectItem_o
        {
            cursor:hand;
            background-color:#FDF2C9
         }
        .selectItem
        {
            cursor:hand;
            background-color:#FFFFFF
        }
    </style>
    <div class="vista__tab_xp vista__tab_container vista__tab_default">
        <div id="selector_tab" class="vista__tab_header">
            <span id="userByOrgTag" class="vista__tab_active"">
                <span class="vista__tab_outer">
                    <span class="vista__tab_inner">
                        <span class="vista__tab_tab">
                        按部门选择用户 
                        </span>
                    </span>
                </span>
            </span>            
        </div>
        <div class="vista__tab_body">
            <div id="selector_0" class="vista__tab_panel">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <div style="padding-top: 5px;">
                            <table cellpadding="1" cellspacing="2" border="0" width="100%">
                                <tr>
                                    <td width="180px">
                                        <div style="width: 100%; height: 320px; vertical-align: top; overflow: auto;">
                                            <uc3:DepartmentTree ID="deptTree" runat="server" ShowCheckBoxes="None" OnNodeClick="DeptTree_NodeClick" />
                                        </div>
                                    </td>
                                    <td valign="top">
                                        <uc2:UserList ID="userList" runat="server" Mode="SingleSelector" OnClientSelectBtnClick="AddItem('用户：%Name%（%DeptFullName%）', '<Actor Type=\'%ActorType%\' ID=\'%ID%\' LoginID=\'%LoginID%\' Name=\'%Name%\' />')" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
        </div>
    </div>
    <div style="padding: 5px; height:100px">
        <table id="selectedTable" class="dg_borderstyle" cellspacing="1" style="background-color:#A0A0A0">            
            <tr id="head">
                <th>用户</th>
                <%--<th>管理范围</th>--%>
                <th>操作</th>
            </tr>
        </table>
    </div>
    
    <script language="javascript" type="text/javascript">
    <!--
        function Save() {
            var userString = "";
            
            $('#selectedTable tbody tr').each(function () {
                if ($(this).attr("id") != 'head') {
                    userString = userString + $(this).attr("id") + ',';
                    userString = userString + $(this).attr("userName") + ',';
                    userString = userString + $(this).attr("scope") + '~';
                }
            });

            window.returnValue = userString;
            window.close();          
                    
        }

        function AddItem(fullname, info) {
            var user = $($.createXMLDocument(info)).find('Actor');
            var id = user.attr('ID');
            var name = user.attr('Name');
            var tbody = $('#selectedTable tbody');
            $("<tr id=" + id + " userName=" + name + " scope='' class=selectItem onmouseover='focusRow(this)' ondblclick='DeleteRow(\"" + id + "\")' onmouseout='blurRow(this)'><td>" + name + "</td><td><a href='javascript:DeleteRow(\"" + id + "\")'>删除</a></td></tr>").appendTo(tbody);
        }

        function setScope(id) {
            var sFeature = "dialogHeight:700px; dialogWidth:900px; center:yes; resizable:yes; scroll:no; status:no;";
            var url = "/Common/ApplicationPages/UserSelector.aspx?mode=MutilSelector&selectorMode=org&rnd=" + Math.random();
            var result = window.showModalDialog(url, null, sFeature);
            var scope = '';
            var scopeName = '';
            if (result) {
                $($.createXMLDocument(result)).find('Actors Actor').each(function () {
                    scope = scope + $(this).attr("ID") + ";";
                    scopeName = scopeName + $(this).attr("Name") + ";";
                });
            }
            $('#' + id).attr("scope", scope);
            $('#' + id+"_Scope").text(scopeName);
        }

        function DeleteRow(id) {
            $('#' + id).remove();
        }

        function focusRow(r) {
            r.className = 'selectItem_o';
        }

        function blurRow(r) {
            r.className = 'selectItem';
        }

        $.createXMLDocument = function (string) {
            var browserName = navigator.appName;
            var doc;
            if (browserName == 'Microsoft Internet Explorer') {
                doc = new ActiveXObject('Microsoft.XMLDOM');
                doc.async = 'false';
                doc.loadXML(string);
            } else {
                doc = (new DOMParser()).parseFromString(string, 'text/xml');
            }
            return doc;
        }
    //-->
    </script>
</asp:Content>

<asp:Content ID="ctFooter"  ContentPlaceHolderID="FooterHolder" runat="server">
<asp:LinkButton ID="btnSave" CssClass="linkbtn" runat="server" OnClientClick="javascript:Save();" 
        CausesValidation="true"><span>保存</span></asp:LinkButton>&nbsp;&nbsp;
<a href="javascript:window.close();" class="linkbtn"><span>关闭</span></a>
</asp:Content>